﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using WpfApp1.Dto;
using WpfApp1.Models;
using WpfApp1.RouteEvnet;

namespace WpfApp1
{
    /// <summary>
    /// TreeViewDemo.xaml 的交互逻辑
    /// </summary>
    public partial class TreeViewDemo : Window
    {
        public TreeViewDemo()
        {
            InitializeComponent();
            InitTreeData();
        }

        public CategoryViewModel SelectProduct;

        public void InitTreeData()
        {
            var categorys = new List<CategoryViewModel>();
            var category = new CategoryDto() {
                Id = "001",
                Name = "这是第一个",
                ParentId = "",
                ChildCategorys = new List<CategoryDto>()
            };

            var category1 = new CategoryDto()
            {
                Id = "0001001",
                Name = "二级分类",
                ParentId = "0001",
                ChildCategorys = new List<CategoryDto>()
            };

            var category2 = new CategoryDto()
            {
                Id = "0001001001",
                Name = "三级分类1",
                ParentId = "0001001",
                ChildCategorys = new List<CategoryDto>()
            };

            var category3 = new CategoryDto()
            {
                Id = "0001001002",
                Name = "三级分类2",
                ParentId = "0001001",
                ChildCategorys = new List<CategoryDto>()
            };

            var category4 = new CategoryDto()
            {
                Id = "0002",
                Name = "第二个",
                ParentId = "",
                ChildCategorys = new List<CategoryDto>()
            };

            var category5 = new CategoryDto()
            {
                Id = "0002001",
                Name = "第二二级分类",
                ParentId = "0002",
                ChildCategorys = new List<CategoryDto>()
            };

            var category6 = new CategoryDto()
            {
                Id = "0002001001",
                Name = "第二三级分类1",
                ParentId = "0002001",
                ChildCategorys = new List<CategoryDto>()
            };

            var category7 = new CategoryDto()
            {
                Id = "0002001002",
                Name = "第二三级分类2",
                ParentId = "0002001",
                ChildCategorys = new List<CategoryDto>()
            };

            category.ChildCategorys.Add(category1);
            category1.ChildCategorys.Add(category2);
            category1.ChildCategorys.Add(category3);
            category4.ChildCategorys.Add(category5);
            category5.ChildCategorys.Add(category6);
            category5.ChildCategorys.Add(category7);

            var data = new ObservableCollection<CategoryViewModel>();
            data.Add(new CategoryViewModel(category));
            data.Add(new CategoryViewModel(category4));
            //var products = new List<CategoryDto>();
            //products.Add(new CategoryDto() {ModelName="112" });
            //products.Add(new CategoryDto() { ModelName = "113" });
            //products.Add(new CategoryDto() { ModelName = "114" });
            //products.Add(new CategoryDto() { ModelName = "115" });
            //products.Add(new CategoryDto() { ModelName = "116" });
            //category.CategoryName = "001";
            //category.ChildCagegorys = products;
            //categorys.Add(category);

            //var category1 = new CategoryViewModel();
            //var products1 = new ObservableCollection<Product>();
            //products1.Add(new Product() { ModelName = "212" });
            //products1.Add(new Product() { ModelName = "213" });
            //products1.Add(new Product() { ModelName = "214" });
            //products1.Add(new Product() { ModelName = "215" });
            //products1.Add(new Product() { ModelName = "216" });
            //category1.CategoryName = "002";
            //category1.ChildCagegorys = products1;
            //categorys.Add(category1);
            treeCategories.ItemsSource = data;
        }

        private void TimeClick(object sender, TimeRouteEventArgs e)
        {
            MessageBox.Show(e.ClickTime.ToLongTimeString());
        }

        public void tree_Click(object sender, RoutedEventArgs e)
        {
            MessageBox.Show("tree_click");
            //var btn = (Button)sender;
            //var name = btn.Name;
            //switch(name)
            //{
            //    case "ok":
            //        if (treeCategories.SelectedItem == null)
            //            break;
            //        var type = treeCategories.SelectedItem.GetType();
            //        if(type.Name == "CategoryViewModel")
            //        {
            //            var category = (CategoryViewModel)treeCategories.SelectedItem;
            //            MessageBox.Show(category.CategoryName);
            //            SelectProduct = category;
            //            this.DialogResult = true;

            //        }
                   
            //        break;
            //    case "cancle":
            //        {
            //            this.Close();
            //        }
            //        break;
            //}
        }
    }
}
